#!/usr/bin/python

"""
	File:		user.py
	
	Class:		CMPS 140 Winter 2011
	Project:	Papa Bot
	Date:		02/13/11
	Authors:	Jason Erickson
	Morgan Davis
	DJ Visbal
	Constantine Perepelitsa
	Jae Kim
	Huu Huynh
	"""

import sqlite3

class User(object):
    """The User Class
		
		The User class keeps track of the cabinet information and user
		preferences for the current user. This is used to save information
        accross multiple states.
		
		Instantiate using User(name) for a new user,
		or else use User.fromName(name) or User.fromID(id).
		
		User.fromName and User.fromID will return None if the user does not
		yet exist.
		
		"""
	
    def __init__(self,db=None,name=None):
        """Initialize user with given name, or create a user with the name."""
        self.db = db
        self.name = name
        self.id = self.db.getUserID(name)
        if self.id == None:
            # create a new user
            self.id = self.db.createUser(name)
	
    def get_cabinet(self):
        return self.db.getCabinet(self.id)
	
    def cabinet_add(self, ingredient_id):
        self.db.addToCabinet(self.id, ingredient_id)
	
    def cabinet_remove(self, ingredient_id):
        self.db.removeFromCabinet(self.id, ingredient_id)

